/**
 * 主题配置方法
 * @author 朱琦
 * @date   时间：2022/7/21
 */
import { ref } from 'vue-demi'
import { hasClass, addClass, removeClass } from '../utils/dom'
import { setThemeStyle } from './themes/theme.config'

const classPrefix = 'microvideo-zhdd-business-'

// 主题名
export const theme = ref('dark')

/**
 * 设置主题
 * @param {String} _theme 主题名
 */
export const setTheme = (_theme) => {
    if (theme.value === _theme) return

    const currentTheme = theme.value

    if (hasClass(document.body, classPrefix + currentTheme)) {
        removeClass(document.body, classPrefix + currentTheme)
    }

    addClass(document.body, classPrefix + _theme)
    theme.value = _theme;
    // document.body.setAttribute('data-mz-theme', _theme)

    setThemeStyle(_theme)
}
